package com.example.fw;

import org.netbeans.jemmy.operators.JButtonOperator;
import org.netbeans.jemmy.operators.JDialogOperator;
import org.netbeans.jemmy.operators.JTextFieldOperator;
import org.netbeans.jemmy.operators.JTreeOperator;

import com.example.utils.SortedListOf;

public class FolderHelper extends HelperBase {

	public FolderHelper(ApplicationManager manager) {
		super(manager);
	}

	public SortedListOf<String> getFolders() {
		SortedListOf<String> list = new SortedListOf<String>();
		JTreeOperator tree = new JTreeOperator(mainFrame);
		Object[] children = tree.getChildren(tree.getRoot());
		for (Object child : children) {
			list.add("" + child);
		}
		return list;
	}

	public String createFolder(String folder) {
		manager.getMenuHelper().pushCreateFolder();
		JDialogOperator dialog = new JDialogOperator(mainFrame);
		new JTextFieldOperator(dialog).setText(folder);
		new JButtonOperator(dialog, "OK").push();
		return waitMessageDialog("Warning", 3000);
	}

	public void deleteFolder(int index) {
		JTreeOperator tree = new JTreeOperator(mainFrame);
		tree.selectRow(index);
		manager.getMenuHelper().pushDelete();
		JDialogOperator dialog = new JDialogOperator(mainFrame);
		new JButtonOperator(dialog, "Yes").push();
	}

	public void createFolders(int amount) {
		for (int i = 0; i < amount; i++) {
			createFolder("folder"+i);
		}
	}

}
